{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import re\n",
    "import time\n",
    "import jieba\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "from langconv import *\n",
    "pd.options.display.max_columns = None"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 105000 entries, 0 to 104999\n",
      "Data columns (total 22 columns):\n",
      "id                                          105000 non-null int64\n",
      "content                                     105000 non-null object\n",
      "location_traffic_convenience                105000 non-null int64\n",
      "location_distance_from_business_district    105000 non-null int64\n",
      "location_easy_to_find                       105000 non-null int64\n",
      "service_wait_time                           105000 non-null int64\n",
      "service_waiters_attitude                    105000 non-null int64\n",
      "service_parking_convenience                 105000 non-null int64\n",
      "service_serving_speed                       105000 non-null int64\n",
      "price_level                                 105000 non-null int64\n",
      "price_cost_effective                        105000 non-null int64\n",
      "price_discount                              105000 non-null int64\n",
      "environment_decoration                      105000 non-null int64\n",
      "environment_noise                           105000 non-null int64\n",
      "environment_space                           105000 non-null int64\n",
      "environment_cleaness                        105000 non-null int64\n",
      "dish_portion                                105000 non-null int64\n",
      "dish_taste                                  105000 non-null int64\n",
      "dish_look                                   105000 non-null int64\n",
      "dish_recommendation                         105000 non-null int64\n",
      "others_overall_experience                   105000 non-null int64\n",
      "others_willing_to_consume_again             105000 non-null int64\n",
      "dtypes: int64(21), object(1)\n",
      "memory usage: 17.6+ MB\n",
      "None\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 15000 entries, 0 to 14999\n",
      "Data columns (total 22 columns):\n",
      "id                                          15000 non-null int64\n",
      "content                                     15000 non-null object\n",
      "location_traffic_convenience                15000 non-null int64\n",
      "location_distance_from_business_district    15000 non-null int64\n",
      "location_easy_to_find                       15000 non-null int64\n",
      "service_wait_time                           15000 non-null int64\n",
      "service_waiters_attitude                    15000 non-null int64\n",
      "service_parking_convenience                 15000 non-null int64\n",
      "service_serving_speed                       15000 non-null int64\n",
      "price_level                                 15000 non-null int64\n",
      "price_cost_effective                        15000 non-null int64\n",
      "price_discount                              15000 non-null int64\n",
      "environment_decoration                      15000 non-null int64\n",
      "environment_noise                           15000 non-null int64\n",
      "environment_space                           15000 non-null int64\n",
      "environment_cleaness                        15000 non-null int64\n",
      "dish_portion                                15000 non-null int64\n",
      "dish_taste                                  15000 non-null int64\n",
      "dish_look                                   15000 non-null int64\n",
      "dish_recommendation                         15000 non-null int64\n",
      "others_overall_experience                   15000 non-null int64\n",
      "others_willing_to_consume_again             15000 non-null int64\n",
      "dtypes: int64(21), object(1)\n",
      "memory usage: 2.5+ MB\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "train = pd.read_csv(\"./data/sentiment_analysis_trainingset.csv\")\n",
    "validation = pd.read_csv(\"./data/sentiment_analysis_validationset.csv\")\n",
    "print(train.info())\n",
    "print(validation.info())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "def trans2simp(line):\n",
    "    line = Converter('zh-hans').convert(line)\n",
    "    return line"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def cut(string):\n",
    "    string = trans2simp(string).replace('\\n', '')\n",
    "    w_list = jieba.cut(string)\n",
    "    return ' '.join(w for w in w_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = train.append(validation).reset_index(drop=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Building prefix dict from the default dictionary ...\n",
      "Loading model from cache C:\\Users\\Dracu\\AppData\\Local\\Temp\\jieba.cache\n",
      "Loading model cost 0.655 seconds.\n",
      "Prefix dict has been built succesfully.\n"
     ]
    }
   ],
   "source": [
    "data['content'] = data['content'].apply(cut)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.to_csv('./data/train.csv', index=False, encoding='utf_8')\n",
    "data[len(data)-15000:len(data)].to_csv('./data/val.csv', index=False, encoding='utf_8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "test = pd.read_csv(\"./data/sentiment_analysis_testa.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "test['content'] = test['content'].apply(cut)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "test.to_csv('./data/test.csv', index=False, encoding='utf_8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}